/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @author: jin Chen 
 * @date: Aug 5, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp.plot.control;

import javax.swing.*;
import java.awt.*;
import java.util.HashSet;

class GreyItemRender extends DefaultListCellRenderer{
        private HashSet indexOfGreyItem=new HashSet();
        private Color specialColor=new Color(150,150,150);
        public void colorItem(int index,boolean grey) {
            if(grey)
                this.indexOfGreyItem.add(new Integer(index));
            else
                this.indexOfGreyItem.remove(new Integer(index));
        }
        public boolean isItemColored(int index ) {
            return this.indexOfGreyItem.contains(new Integer(index));
        }
        public Component getListCellRendererComponent(
               JList list,
           Object value,
               int index,
               boolean isSelected,
               boolean cellHasFocus)
           {

               //Componentsuper.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
            setComponentOrientation(list.getComponentOrientation());
            if (isSelected) {
                setBackground(list.getSelectionBackground());
                //setForeground(list.getSelectionForeground());
                if(this.isItemColored(index) ) {
                    setForeground(specialColor );
                }
                else
                    setForeground(list.getForeground());
            }
            else {

                setBackground(list.getBackground());
                if(this.isItemColored(index) ) {
                    setForeground(specialColor );
                }
                else
                    setForeground(list.getForeground());
            }

            if (value instanceof Icon) {
                setIcon((Icon)value);
                setText("");
            }
            else {
                setIcon(null);
                setText((value == null) ? "" : value.toString());
            }

            setEnabled(list.isEnabled());
            setFont(list.getFont());
            setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);

            return this;

           }

    }

